$(function() {
	$("#jqGrid").jqGrid({
		url: baseURL + 'wisarchivestask/list/2',
		datatype: "json",
		colModel: [			
			{ label: 'pid', name: 'pid', index: 'pid', width: 50, key: true ,hidden:true},
			{ label: '', name: 'sysSeq', index: 'sysSeq', width: 80 ,hidden:true}, 			
			{ label: '反映类别', name: 'taskType', index: 'taskType', width: 80 }, 			
			{ label: '反映人', name: 'taskReflectPerson', index: 'taskReflectPerson', width: 60 }, 			
			{ label: '反映人组别', name: 'taskReflectPersonGroup', index: 'taskReflectPersonGroup', width: 80 }, 			
			{ label: '反映人电话', name: 'taskReflectPersonMobile', index: 'taskReflectPersonMobile', width: 80 }, 			
			{ label: '反映内容', name: 'taskReflectContent', index: 'taskReflectContent', width: 80 }, 			
			{ label: '受理时间', name: 'taskReceiveTime', index: 'taskReceiveTime', width: 80 }, 			
			{ label: '受理人', name: 'taskReceivePerson', index: 'taskReceivePerson', width: 60 }, 			
			{ label: '事项明确时间', name: 'taskDealTimeStart', index: 'taskDealTimeStart', width: 80 ,hidden:true}, 			
			{ label: '事项办结时间', name: 'taskDealTimeEnd', index: 'taskDealTimeEnd', width: 80 ,hidden:true}, 			
			{ label: '承办责任人', name: 'taskResponsibler', index: 'taskResponsibler', width: 80 ,hidden:true}, 			
			{ label: '承办责任人电话', name: 'taskResponsiblerMobile', index: 'taskResponsiblerMobile', width: 80 ,hidden:true}, 			
			{ label: '办理情况', name: 'taskDealResults', index: 'taskDealResults', width: 80 ,hidden:true}, 			
			{ label: '实际办结时间', name: 'taskOverTime', index: 'taskOverTime', width: 80 ,hidden:true}, 			
			{ label: '负责人', name: 'taskHeader', index: 'taskHeader', width: 60 ,hidden:true}, 			
			{ label: '答复时间', name: 'taskAnswerTime', index: 'taskAnswerTime', width: 80 ,hidden:true}, 			
			{ label: '答复方式', name: 'taskAnswerWay', index: 'taskAnswerWay', width: 80 ,hidden:true}, 			
			{ label: '短信内容', name: 'taskSmsContent', index: 'taskSmsContent', width: 80 ,hidden:true}, 			
			{ label: '反映人满意度', name: 'taskReflectSatisfac', index: 'taskReflectSatisfac', width: 80 ,hidden:true}, 			
			{ label: '任务状态', name: 'taskStatus', index: 'taskStatus', width: 80 ,hidden:true}, 			
			{ label: '', name: 'sysCreateTime', index: 'sysCreateTime', width: 80 ,hidden:true}, 			
			{ label: '', name: 'lastModifyTime', index: 'lastModifyTime', width: 80 ,hidden:true},
			{
				label: '操作',
				name: '操作',
				index: '',
				width: 80,
				sortable:false,
				formatter: function(cellvalue, options, rowObject) {
					var buttons= '<button style="border:0px;padding:0px" class="btn btn-default" onclick="edit(\''+rowObject.pid+'\')"><i class="fa fa-pencil-square-o"></i></button>';
					return buttons;
				}
			}
        ],
		viewrecords: true,
		height: 385,
		rowNum: 10,
		rowList: [10, 30, 50],
		rownumbers: true,
		rownumWidth: 25,
		autowidth: true,
		multiselect: false,
		pager: "#jqGridPager",
		jsonReader: {
			root: "page.list",
			page: "page.currPage",
			total: "page.totalPage",
			records: "page.totalCount"
		},
		prmNames: {
			page: "page",
			rows: "limit",
			order: "order"
		},
		gridComplete: function() {
			//隐藏grid底部滚动条
			$("#jqGrid").closest(".ui-jqgrid-bdiv").css({
				"overflow-x": "hidden"
			});
		}
	});
});

var vm = new Vue({
	el: '#rrapp',
	data: {
		showList: true,
		title: null,
		wisArchivesTask: {}
	},
	methods: {
		query: function() {
			vm.reload();
		},
		add: function() {
			vm.showList = false;
			vm.title = "新增";
			vm.wisArchivesTask = {};
		},
		update: function(event) {
			var pid = getSelectedRow();
			if(pid == null) {
				return;
			}
			vm.showList = false;
			vm.title = "修改";

			vm.getInfo(pid)
		},
		saveOrUpdate: function(event) {
			var url = vm.wisArchivesTask.pid == null ? "wisarchivestask/save" : "wisarchivestask/update";
			$.ajax({
				type: "POST",
				url: baseURL + url,
				contentType: "application/json",
				data: JSON.stringify(vm.wisArchivesTask),
				success: function(r) {
					if(r.code === 0) {
						alert('操作成功', function(index) {
							vm.reload();
						});
					} else {
						alert(r.msg);
					}
				}
			});
		},
		del: function(event) {
			var pids = getSelectedRows();
			if(pids == null) {
				return;
			}

			confirm('确定要删除选中的记录？', function() {
				$.ajax({
					type: "POST",
					url: baseURL + "wisarchivestask/delete",
					contentType: "application/json",
					data: JSON.stringify(pids),
					success: function(r) {
						if(r.code == 0) {
							alert('操作成功', function(index) {
								$("#jqGrid").trigger("reloadGrid");
							});
						} else {
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(pid) {
			$.get(baseURL + "wisarchivestask/info/" + pid, function(r) {
				vm.wisArchivesTask = r.wisArchivesTask;
				//初始化组件的值
				initComponent();
			});
		},
		reload: function(event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam', 'page');
			$("#jqGrid").jqGrid('setGridParam', {
				page: page
			}).trigger("reloadGrid");
		}
	}
});